/**
 *
 *  读取文件夹并运行服务
 */

const path = require('path')
const util = require('util')

// 启动的项目名称
var sub_apps  = [
  'web-microApp-module-basic',
  'web-microApp-module-userConf',
  'web-microApp-module-user',
]

console.log(`即将进入所有模块并启动服务：${JSON.stringify(sub_apps)} ing...`)
const exec = util.promisify(require('child_process').exec)
function start() {
  sub_apps.forEach(async i => {
    console.log(`${i} 开始启动 后续不再提示 请自行查看`)
    const { stdout, stderr } = await exec('npm start', { cwd: path.resolve(i) })
    console.log(i, 'success', stdout)
    console.error(i, 'error', stderr)
  })
}
start()

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at: Promise', p, 'reason:', reason)
  // application specific logging, throwing an error, or other logic here
})
